﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FamilyBook.Core;
using FamilyBook.Core.Configuration;
using FamilyBook.Core.Entities;
using FamilyBook.Core.Services;
using FamilyBook.Infrastructure;
using FamilyBook.UI.WPF.Views;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Unity;
using FamilyBook.Core.Repositories;
using FamilyBook.Repository.EF;

namespace FamilyBook.UI.WPF.Modules
{
    //[Module(ModuleName = "AccountsListModule")]
    //[ModuleDependency()]
    public class AccountsListModule : IModule
    {
        private readonly IRegionManager _regionManager;
        private readonly IUnityContainer _iocContainer;

        public AccountsListModule(IUnityContainer iocContainer, IRegionManager regionManager)
        {
            _regionManager = regionManager;
            _iocContainer = iocContainer;
        }

        public void Initialize()
        {
            //_iocContainer.RegisterType<IConfiguration, AppConfig>(new InjectionConstructor(new InjectionParameter<System.Configuration.Configuration>(null)));
            //_iocContainer.RegisterType<IDbSession, DbSession>();
            //_iocContainer.RegisterType(typeof(IGeneralRepository<,>), typeof(GeneralRepository<,>));

            //_iocContainer.RegisterType(typeof(GeneralService<,>));
            //_iocContainer.RegisterType<SequenceService>();
            //_iocContainer.RegisterType(typeof(AccountService<>));
            

            //var serviceFactory = new ServiceFactory();

            //IDbSession dbSession = _iocContainer.Resolve<IDbSession>();
            //IDbSession dbSession = new DbSession(new AppConfig(null));
            //var acctList = _iocContainer.Resolve<AccountsList>(new DependencyOverride<IDbSession>(dbSession));
            //var acctList = _iocContainer.Resolve<AccountsList>(new ParameterOverrides() {{"dbSession", dbSession}});

            //var ea = _iocContainer.Resolve<IEventAggregator>();
            _regionManager.RegisterViewWithRegion("AccountsListView", GetAccountsListView);
        }

        private AccountsListView GetAccountsListView()
        {
            var dbSession = _iocContainer.Resolve<IDbSession>();
            return _iocContainer.Resolve<AccountsListView>(new DependencyOverride<IDbSession>(dbSession));
        }
    }
}
